package com.ruoyi.training.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.training.dto.ClassStudentDto;
import com.ruoyi.training.vo.StudentTrainingQueryVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.training.domain.PracticeClass;
import com.ruoyi.training.service.IPracticeClassService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 实践预约班级中间Controller
 *
 * @author WorrilessGo
 * @date 2025-10-14
 */
@RestController
@RequestMapping("/practiceClass")
public class PracticeClassController extends BaseController
{
    @Autowired
    private IPracticeClassService practiceClassService;

    /**
     * 查询实践预约班级中间列表
     */
    @RequiresPermissions("training:practiceClass:list")
    @GetMapping("/list")
    public TableDataInfo list(PracticeClass practiceClass)
    {
        startPage();
        List<PracticeClass> list = practiceClassService.selectPracticeClassList(practiceClass);
        return getDataTable(list);
    }

    /**
     * 添加预约时，查询当前实践分配班级中的学员
     * lqx
     */
//    @RequiresPermissions("training:practiceClass:query")
    @GetMapping("/selectStudents")
    public TableDataInfo selectStudentsWhenAdd( StudentTrainingQueryVo studentTrainingQueryVo) {
        startPage();
        List<ClassStudentDto> list = practiceClassService.selectStudentsWhenAdd(studentTrainingQueryVo);
        return getDataTable(list);
    }

    /**
     * 导出实践预约班级中间列表
     */
    @RequiresPermissions("training:practiceClass:export")
    @Log(title = "实践预约班级中间", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PracticeClass practiceClass)
    {
        List<PracticeClass> list = practiceClassService.selectPracticeClassList(practiceClass);
        ExcelUtil<PracticeClass> util = new ExcelUtil<PracticeClass>(PracticeClass.class);
        util.exportExcel(response, list, "实践预约班级中间数据");
    }

    /**
     * 获取实践预约班级中间详细信息
     */
    @RequiresPermissions("training:practiceClass:query")
    @GetMapping(value = "/{practiceClassId}")
    public AjaxResult getInfo(@PathVariable("practiceClassId") String practiceClassId)
    {
        return success(practiceClassService.selectPracticeClassByPracticeClassId(practiceClassId));
    }

    /**
     * 新增实践预约班级中间
     */
    @RequiresPermissions("training:practiceClass:add")
    @Log(title = "实践预约班级中间", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PracticeClass practiceClass)
    {
        return toAjax(practiceClassService.insertPracticeClass(practiceClass));
    }

    /**
     * 修改实践预约班级中间
     */
    @RequiresPermissions("training:practiceClass:edit")
    @Log(title = "实践预约班级中间", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PracticeClass practiceClass)
    {
        return toAjax(practiceClassService.updatePracticeClass(practiceClass));
    }

    /**
     * 删除实践预约班级中间
     */
    @RequiresPermissions("training:practiceClass:remove")
    @Log(title = "实践预约班级中间", businessType = BusinessType.DELETE)
	@DeleteMapping("/{practiceClassIds}")
    public AjaxResult remove(@PathVariable String[] practiceClassIds)
    {
        return toAjax(practiceClassService.deletePracticeClassByPracticeClassIds(practiceClassIds));
    }
}
